package com.cea.papyrus.core.commands.copypaste;

import java.util.Collection;

import org.eclipse.gef.commands.Command;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.editor.ModelManager;

public class CopyToClipboardCommand  extends Command {

	/** wrapped EMF command */
	protected org.eclipse.emf.common.command.Command emfCopyCommand;

	/**
	 * Constructs a Command with the specified label.
	 * @param label the Command's label
	 */
	public CopyToClipboardCommand (Collection collection, ModelManager modelManager) {
		setLabel("Copy set of elements");
		if(collection.size() >0 ) {
			Element[] elements =  (Element[]) collection.toArray(new Element[] {});
			Element element;
			if(elements.length != 0) {
				element = elements[0];  
			} else {
				throw new RuntimeException("size should be greater than 0");
			}
			emfCopyCommand= org.eclipse.emf.edit.command.CopyToClipboardCommand.create(modelManager.getDiResourceSet().getEditingDomain(), collection);
		} else throw new RuntimeException("collection should not be empty");
	}

	/**
	 * Constructs a Command with the specified label.
	 * @param label the Command's label
	 */
	public CopyToClipboardCommand (Element umlElement, ModelManager modelManager) {
		setLabel("Copy "+modelManager.getLabelProvider().getText(umlElement));
		emfCopyCommand= org.eclipse.emf.edit.command.CopyToClipboardCommand.create(modelManager.getDiResourceSet().getEditingDomain(), umlElement);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canExecute()
	 */
	@Override
	public boolean canExecute() {
		return emfCopyCommand.canExecute();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#canUndo()
	 */
	@Override
	public boolean canUndo() {
		return emfCopyCommand.canUndo();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#dispose()
	 */
	@Override
	public void dispose() {
		emfCopyCommand.dispose();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#execute()
	 */
	@Override
	public void execute() {
		emfCopyCommand.execute();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#redo()
	 */
	@Override
	public void redo() {
		emfCopyCommand.redo();
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
	@Override
	public void undo() {
		emfCopyCommand.undo();
	}



}
